<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="仓库名称" prop="baseName">
        <el-input
          v-model="queryParams.baseName"
          placeholder="请输入仓库名称"
          clearable
          @keyup.enter.native="handleQuery"
        />

      </el-form-item>
      <el-form-item label="仓库状态" prop="baseState">
        <el-input
          v-model="queryParams.baseState"
          placeholder="请输入仓库状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责人" prop="baseCharge">
        <el-input
          v-model="queryParams.baseCharge"
          placeholder="请输入负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['system:base:add']"-->
<!--        >新增</el-button>-->
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:base:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:base:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:base:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="baseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编码" align="center" prop="baseId" />
      <el-table-column label="仓库名称" align="center" prop="baseName" />
      <el-table-column label="库存容量" align="center" prop="baseCapacity" />
      <el-table-column label="使用情况" align="center" prop="baseCase" />
      <el-table-column label="仓库状态" align="center" prop="baseState" />
      <el-table-column label="实时库存统计" align="center" prop="baseCount" />
      <el-table-column label="最近变动时间" align="center" prop="baseTime" />
      <el-table-column label="负责人" align="center" prop="baseCharge" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">

        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:base:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:base:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <img src="@/assets/images/shuju.png" alt="你的图片">
    <!-- 添加或修改数据统计对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">




        <el-form-item label="仓库名称" prop="baseName">
          <el-select v-model="form.baseName" placeholder="请选择仓库名称">
            <el-option
              v-for="item in options"
              :key="item.stockroomId"
              :label="item.stockroomName"
              :value="item.stockroomId">
            </el-option>
          </el-select>



<!--        <el-input v-model="form.baseName" placeholder="请输入仓库名称" />-->
        </el-form-item>
        <el-form-item label="库存容量" prop="baseCapacity">
          <el-input v-model="form.baseCapacity" placeholder="请输入库存容量" />
        </el-form-item>
        <el-form-item label="使用情况" prop="baseCase">
          <el-input v-model="form.baseCase" placeholder="请输入使用情况" />
        </el-form-item>
        <el-form-item label="仓库状态" prop="baseState">
          <el-input v-model="form.baseState" placeholder="请输入仓库状态" />
        </el-form-item>
        <el-form-item label="实时库存统计" prop="baseCount">
          <el-input v-model="form.baseCount" placeholder="请输入实时库存统计" />
        </el-form-item>
        <el-form-item label="最近变动时间" prop="baseTime">
          <el-input v-model="form.baseTime" placeholder="请输入最近变动时间" />
        </el-form-item>
        <el-form-item label="负责人" prop="baseCharge">
          <el-input v-model="form.baseCharge" placeholder="请输入负责人" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>





<!--  <el-progress type="dashboard" :percentage="percentage" :color="colors"></el-progress>-->
<!--  <div>-->
<!--    <el-button-group>-->
<!--      <el-button icon="el-icon-minus" @click="decrease"></el-button>-->
<!--      <el-button icon="el-icon-plus" @click="increase"></el-button>-->
<!--    </el-button-group>-->
<!--  </div>-->





<!--  <div class="demo-image__placeholder">-->
<!--    <div class="block">-->
<!--      <span class="demonstration">默认</span>-->
<!--      <el-image :src="src"></el-image>-->
<!--    </div>-->
<!--    <div class="block">-->
<!--      <span class="demonstration">自定义</span>-->
<!--      <el-image :src="src">-->
<!--        <div slot="placeholder" class="image-slot">-->
<!--          加载中<span class="dot">...</span>-->
<!--        </div>-->
<!--      </el-image>-->
<!--    </div>-->
<!--  </div>-->




<!--  <div class="demo-image__preview">-->
<!--    <el-image-->
<!--      style="width: 100px; height: 100px"-->
<!--      :src="url"-->
<!--      :preview-src-list="srcList">-->
<!--    </el-image>-->
<!--  </div>-->






</template>


<div class="body">
<img
  src="@/assets/images/pay.png"
  alt="donate"
  width="100%"
/>
</div>



<div class="block">
<span class="demonstration">默认不区分颜色</span>
<el-rate v-model="value1"></el-rate>
</div>
<div class="block">
<span class="demonstration">区分颜色</span>
<el-rate
  v-model="value2"
  :colors="colors">
</el-rate>
</div>

<div class="demo-image">
<div class="block" v-for="fit in fits" :key="fit">
  <span class="demonstration">{{ fit }}</span>
  <el-image
    style="width: 100px; height: 100px"
    :src="url"
    :fit="fit"></el-image>
</div>
</div>

<script>
export default {
  data() {
    return {
      fits: ['fill', 'contain', 'cover', 'none', 'scale-down'],
      url: 'https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg'
    }
  }
}
</script>



<script>
import {listStock, listBase, getBase, delBase, addBase, updateBase } from "@/api/system/base";

export default {
  name: "Base",
  data() {
    return {

      value1: null,
      value2: null,
      colors: ['#99A9BF', '#F7BA2A', '#FF9900'] , // 等同于 { 2: '#99A9BF', 4: { value: '#F7BA2A', excluded: true }, 5: '#FF9900' }




      // percentage: 10,
      // colors: [
      //   {color: '#f56c6c', percentage: 20},
      //   {color: '#e6a23c', percentage: 40},
      //   {color: '#5cb87a', percentage: 60},
      //   {color: '#1989fa', percentage: 80},
      //   {color: '#6f7ad3', percentage: 100}
      // ],


      // src: 'https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg',
      //
      //
      // url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
      // srcList: [
      //   'https://fuss10.elemecdn.com/8/27/f01c15bb73e1ef3793e64e6b7bbccjpeg.jpeg',
      //   'https://fuss10.elemecdn.com/1/8e/aeffeb4de74e2fde4bd74fc7b4486jpeg.jpeg'
      // ],




      options:[],  //表示存储所有的仓库信息
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 数据统计表格数据
      baseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        baseName: null,
        baseState: null,
        baseCharge: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        baseName: [
          { required: true, message: "仓库名称不能为空", trigger: "blur" }
        ],
        baseCapacity: [
          { required: true, message: "库存容量不能为空", trigger: "blur" }
        ],
        baseCase: [
          { required: true, message: "使用情况不能为空", trigger: "blur" }
        ],
        baseState: [
          { required: true, message: "仓库状态不能为空", trigger: "blur" }
        ],
        baseCount: [
          { required: true, message: "实时库存统计不能为空", trigger: "blur" }
        ],
        baseTime: [
          { required: true, message: "最近变动时间不能为空", trigger: "blur" }
        ],
        baseCharge: [
          { required: true, message: "负责人不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {

    increase() {
      this.percentage += 10;
      if (this.percentage > 100) {
        this.percentage = 100;
      }
    },
    decrease() {
      this.percentage -= 10;
      if (this.percentage < 0) {
        this.percentage = 0;
      }
    },








    /** 查询数据统计列表 */
    getList() {
      this.loading = true;
      listBase(this.queryParams).then(response => {
        this.baseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        baseId: null,
        baseName: null,
        baseCapacity: null,
        baseCase: null,
        baseState: null,
        baseCount: null,
        baseTime: null,
        baseCharge: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.baseId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加数据统计";
      //调用后端查询所有的仓库信息,以下拉框形式进行展示
listStock().then(aaa=>{
  console.log("结果为：",JSON.stringify(aaa))
  this.options=aaa.data
})







    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const baseId = row.baseId || this.ids
      getBase(baseId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改数据统计";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.baseId != null) {
            updateBase(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBase(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const baseIds = row.baseId || this.ids;
      this.$modal.confirm('是否确认删除数据统计编号为"' + baseIds + '"的数据项？').then(function() {
        return delBase(baseIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/base/export', {
        ...this.queryParams
      }, `base_${new Date().getTime()}.xlsx`)






    }
  }
};
</script>





